/**
 * Created by fusy on 2016/7/7.
 */

import React from 'react';
import {Form,Col,Input,Button,Collapse,Row,Modal,Select,Tree} from 'antd';
import util from 'util';
import menus from 'menu';
import {FormSelect} from 'kpl';

var FormItem = Form.Item;
var Panel = Collapse.Panel;
const Option = Select.Option;
const TreeNode = Tree.TreeNode;

@Form.create() class Search extends React.Component {
    constructor(props) {
        super(props);
    }

    componentDidMount() {
        var {setFieldsValue} = this.props.form;
        setFieldsValue(this.props.data);
    }

    reset(e) {
        e.preventDefault();
        var {setFieldsValue} = this.props.form;
        setFieldsValue({
            dict: "",
            dictname: ""
        });
    }

    search(e) {
        e.preventDefault();
        console.log('接受到表单值', this.props.form.getFieldsValue());
        this.props.search(this.props.form.getFieldsValue());
    }

    render() {
        const {getFieldProps} =this.props.form;
        const formItemLayout = {
            labelCol: {span: 8},
            wrapperCol: {span: 14}
        };
        return (
            <Collapse defaultActiveKey={['1']}>
                <Panel header="数据字典信息查询" key="1">
                    <Form inline className="ant-advanced-search-form">
                        <Row>
                            <Col span={8}>
                                <FormItem label="字典标识：" {...formItemLayout}>
                                    <Input
                                        {...getFieldProps('dict')}
                                        />
                                </FormItem>
                            </Col>
                            <Col span={8}>
                                <FormItem label="字典名称：" {...formItemLayout}>
                                    <Input
                                        {...getFieldProps('dictname')}
                                        />
                                </FormItem>
                            </Col>
                            <Col span={8}>
                                <Button className="btnMarginRright" type="primary" htmlType="submit"
                                        onClick={this.search.bind(this)}>搜索</Button>
                                <Button htmlType="submit" onClick={this.reset.bind(this)}>重置</Button>
                            </Col>
                        </Row>
                    </Form>
                </Panel>
            </Collapse>
        );
    }
}

@Form.create() class DictForm extends React.Component {

    constructor(props) {
        super(props);
    }

    componentDidMount() {
        var {setFieldsValue} = this.props.form;
        setFieldsValue(this.props.data);

        console.log("下拉框数据：",this.props.optionData);
    }

    render() {

        const formItemLayout = {
            labelCol: {span: 6},
            wrapperCol: {span: 14}
        };

        const { getFieldProps, getFieldError, isFieldValidating } = this.props.form;
        const dictProps = getFieldProps('dict', {
            rules: [
                {required: true, message: '请输入字典标识'}
            ]
        });
        const dictNameProps = getFieldProps('dictname', {
            rules: [
                {required: true, min: 0, message: '请输入字典名称'}
            ]
        });
        const dictGroupProps = getFieldProps('groupdict', {
            rules: [
                {required: false, min: 0, message: '请选择分组'}
            ]
        });

        return (
            <Form horizontal form={this.props.form}>
                <FormItem label="字典标识" {...formItemLayout} hasFeedback
                          help={isFieldValidating('dict') ? '校验中1...' : (getFieldError('dict') || []).join(', ')}>
                    <Input disabled={!this.props.isAdd} {...dictProps} placeholder="请输入字典标识"/>
                </FormItem>
                <FormItem label="字典名称"
                    {...formItemLayout}
                          hasFeedback
                          help={isFieldValidating('dictname') ? '校验中...' : (getFieldError('dictname') || []).join(', ')}>
                    <Input {...dictNameProps} placeholder="请输入字典名称"/>
                </FormItem>


                {/*  <FormItem label="字典分组"  {...formItemLayout} >
                    <FormSelect {...getFieldProps('groupdict', {rules: []})}
                           propsKey='groupdict'
                           form={this.props.form}
                           optionData={this.props.optionData}
                           >
                    </FormSelect>
                </FormItem> */}

            </Form>
        );
    }
}
@Form.create() class ChildrenForm extends React.Component {
    constructor(props) {
        super(props);
    }

    componentDidMount() {
        var {setFieldsValue} = this.props.form;
        setFieldsValue(this.props.data);
    }

    render() {
        const formItemLayout = {
            labelCol: {span: 6},
            wrapperCol: {span: 14}
        };

        const { getFieldProps, getFieldError, isFieldValidating } = this.props.form;
        const itemValProps = getFieldProps('itemval', {
            rules: [
                {required: true, message: '请输入子项值'}
            ]
        });
        const itemKeyProps = getFieldProps('itemkey', {
            rules: [
                {required: true, min: 0, message: "请输入子项键"}
            ]
        });
        const dictProps = getFieldProps('dict', {
            rules: [
                {required: true, min: 0, message: '请输入字典标识'}
            ]
        });

        return (
            <Form horizontal form={this.props.form}>
                <FormItem label="子项值"
                    {...formItemLayout}
                          hasFeedback
                          help={isFieldValidating('itemkey') ? '校验中...' : (getFieldError('itemkey') || []).join(', ')}>
                    <Input disabled={!this.props.isAdd}
                        {...itemKeyProps} placeholder="请输入子项键"/>
                </FormItem>
                <FormItem label="子项名称" {...formItemLayout} hasFeedback
                          help={isFieldValidating('dict') ? '校验中1...' : (getFieldError('itemval') || []).join(', ')}>
                    <Input {...itemValProps} placeholder="请输入子项值"/>
                </FormItem>

                {/* <FormItem label="字典标识" {...formItemLayout}
                          hasFeedback
                          help={isFieldValidating('dict') ? '校验中...' : (getFieldError('dict') || []).join(', ')}>
                    <Input {...dictProps} placeholder="" disabled={true}/>
                </FormItem>*/}
            </Form>
        );
    }
}

export {Search,DictForm,ChildrenForm}